<?php

namespace app\utils\ui\native_element;

use app\utils\ui\UIView;
use app\utils\ui\VueView;

/**
 * 列表
 */
class UIList implements UIView{

    /**
     * @var array
     */
    public $child;

    public function __construct(array $child) 
    {
        $this->child=$child;
    }
    public function render(){
        $html2 = '';
        foreach($this->child as $child){
            if($child instanceof UIView){
                $html2.=$child->render();
            }
        }
        return $html2;
    }
    
    public function data()
    {
        if($this->child){
            if(is_array($this->child)){
                $list = array();
                foreach($this->child as $child){
                    if($child instanceof UIView){
                        $list = array_merge($list,$child->data());
                    }
                }
                return $list;
            }else{
                return $this->child->data();
            }
        }
        return array();
    }
    
    /**
     * vueview 需要
     */
    public function method()
    {
        $list=array();
        if(is_array($this->child)){
            foreach($this->child as $child){
                if($child instanceof VueView){
                    $list2 = $child->method();
                    foreach($list2 as $v){
                        $list[]=$v;
                    }
                }
            }
        }
        if($this->child instanceof VueView){
            $list2 = $this->child->method();
            foreach($list2 as $v){
                $list[]=$v;
            }
        }
        return $list;
    }
}